/**
 * @param {number} n
 * @param {number[][]} roads
 * @return {number}
 */
var maximalNetworkRank = function (n, roads) {
  let arr = new Array(n).fill(0)
  let matrix = new Array(n).fill(0).map(()=>new Array(n).fill(0))
  for (const road of roads) {
    matrix[road[0]][road[1]]=true
    matrix[road[1]][road[0]]=true
    arr[road[0]]++
    arr[road[1]]++
  }

  let max = 0
  for (let i=0;i<n;i++) {
    for(let j=i+1;j<n;j++){
      let rank = arr[i]+arr[j]-matrix[i][j]?1:0
      max = Math.max(max,rank)
    }
  }
  return max
}
maximalNetworkRank(4, 
  [[0,1],[0,3],[1,2],[1,3]]
)
